package com.ruoyi.education.controller;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.io.IOException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.education.utils.AESUtil;
import com.ruoyi.education.utils.Base58Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.education.domain.Assist;
import com.ruoyi.education.service.IAssistService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 帮扶管理Controller
 * 
 * @author imachen
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/assist")
public class AssistController extends BaseController
{
    @Autowired
    private IAssistService assistService;

    /**
     * 查询帮扶管理列表
     */
    @RequiresPermissions("education:assist:list")
    @GetMapping("/list")
    public TableDataInfo list(Assist assist)
    {
        startPage();
        List<Assist> list = assistService.selectAssistList(assist);
        return getDataTable(list);
    }

    /**
     * 导出帮扶管理列表
     */
    @RequiresPermissions("education:assist:export")
    @Log(title = "帮扶管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Assist assist)
    {
        List<Assist> list = assistService.selectAssistList(assist);
        ExcelUtil<Assist> util = new ExcelUtil<Assist>(Assist.class);
        util.exportExcel(response, list, "帮扶管理数据");
    }

    /**
     * 获取帮扶管理详细信息
     */
    @RequiresPermissions("education:assist:query")
    @GetMapping(value = "/getAssistByCode/{code}")
    public AjaxResult getAssistByCode(@PathVariable("code") String code) throws Exception {
        //进行解密
        byte[] decode = Base58Util.decode(code);
        Long id = AESUtil.decryptId(decode);
        return AjaxResult.success(assistService.getAssistByCode(id));
    }


    /**
     * 获取帮扶管理详细信息
     */
    @RequiresPermissions("education:assist:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assistService.selectAssistById(id));
    }

    /**
     * 新增帮扶管理
     */
    @RequiresPermissions("education:assist:add")
    @Log(title = "帮扶管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Assist assist)
    {

        return toAjax(assistService.insertAssist(assist));
    }

    /**
     * 修改帮扶管理
     */
    @RequiresPermissions("education:assist:edit")
    @Log(title = "帮扶管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Assist assist) throws Exception {
        return toAjax(assistService.updateAssist(assist));
    }

    /**
     * 删除帮扶管理
     */
    @RequiresPermissions("education:assist:remove")
    @Log(title = "帮扶管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assistService.deleteAssistByIds(ids));
    }
}
